ass Solution {
public:
    int romanToInt(string s) {
    //通常情况下，罗马数字中小的数字在大的数字的右边
    //IV == 4 IX == 9
    //XL == 40 XC == 90
    //CD == 400 CM == 900
    //思路是如果出现I就X，C就先判断上面那几种 
    //如果和之前是相同的那就加和
    int res = 0;
    int i = 0;
    while (s[i])
    {
        if (i <= s.size() - 1 && s[i] == 'I' && s[i + 1] == 'V')
        {
            res += 4;
            i += 2;
            continue;
        }
        if (i <= s.size() - 1 && s[i] == 'I' && s[i + 1] == 'X')
        {
            res += 9;
            i += 2;
            continue;
        }
        if (i <= s.size() - 1 && s[i] == 'X' && s[i + 1] == 'L')
        {
            res += 40;
            i += 2;
            continue;
        }
        if (i <= s.size() - 1 && s[i] == 'X' && s[i + 1] == 'C')
        {
            res += 90;
            i += 2;
            continue;
        }
        if (i <= s.size() - 1 && s[i] == 'C' && s[i + 1] == 'D')
        {
            res += 400;
            i += 2;
            continue;
        }
        if (i <= s.size() - 1 && s[i] == 'C' && s[i + 1] == 'M')
        {
            res += 900;
            i += 2;
            continue;
        }
        //进入正常判断逻辑
        if (s[i] == 'I')
        {
            while (s[i] == 'I') { i++; res += 1; }
            continue;
        }
        else if (s[i] == 'V')
        {
            while (s[i] == 'V') { i++; res += 5; }
            continue;
        }
        else if (s[i] == 'X')
        {
            while (s[i] == 'X') { i++; res += 10; }
            continue;
        }
        else if (s[i] == 'L')
        {
            while (s[i] == 'L') { i++; res += 50; }
            continue;
        }
        else if (s[i] == 'C')
        {
            while (s[i] == 'C') { i++; res += 100; }
            continue;
        }
        else if (s[i] == 'D')
        {
            while (s[i] == 'D') { i++; res += 500; }
            continue;
        }
        else if (s[i] == 'M')
        {
            while (s[i] == 'M') { i++; res += 1000; }
            continue;
        }

    }
    return  res;
}
};
